package com.home.free.util;

import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页的数据返回
 * @author gaotianjie
 */
public class PageRet<T> implements Serializable {
    /**
     * 成功
     */
    private Boolean success;
    /**
     * 返回失败码
     */
    private Integer errorCode;
    /**
     * 错误的消息
     */
    private String message;
    /**
     * 分页的内容
     */
    private T body;
    /**
     * 总条数
     */
    private Integer total;

    /**
     * 分页返回失败的接口
     *
     * @param errorCode
     * @param message
     * @param <T>
     * @return
     */
    public static <T> PageRet<T> retFalse(Integer errorCode, String message) {
        PageRet<T> ret = new PageRet<>();
        ret.setSuccess(Boolean.FALSE);
        ret.setErrorCode(errorCode);
        ret.setMessage(message);
        ret.setTotal(0);
        return ret;
    }

    public static <T> PageRet<List<T>> retTure() {
        PageRet<List<T>> ret = new PageRet<>();
        ret.setSuccess(Boolean.TRUE);
        ret.setBody(new ArrayList<>());
        ret.setTotal(0);
        return ret;
    }

    /**
     * 分页返回成功的接口
     * @param body
     * @param total
     * @return
     */
    public static <T> PageRet<T> retTure(T body, Integer total) {
        PageRet<T> ret = new PageRet<>();
        ret.setSuccess(Boolean.TRUE);
        ret.setBody(body);
        ret.setTotal(total);
        return ret;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }
}
